package cn.lcfms.cms.model;

import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.lcfms.app.admin.bean.ArticleBean;
import cn.lcfms.bin.service.BaseService;
import cn.lcfms.cms.CmsDataBase;

public class GetDetails  extends CmsDataBase{

	public GetDetails(HttpServletRequest request, HttpServletResponse response, int id, BaseService service) {
		super(request, response, id, service);
	}

	@Override
	public void data() {
		ArticleBean bean=service.selectOne(ArticleBean.class, id);
		request.setAttribute("article", bean);
		service.setData(id).sql("(SELECT id,title FROM articles a WHERE id<#{id} ORDER BY id DESC LIMIT 0,1) UNION (SELECT id,title FROM articles b WHERE id>#{id} LIMIT 0,1)");
		List<HashMap<String, Object>> result = service.getResult();
		result.forEach((HashMap<String, Object> map)->{
    		int i=(int) map.get("id");
    		if(i<id) {
    			request.setAttribute("pre", map);
    		}
    		if(i>id) {
    			request.setAttribute("next", map);
    		}
    	});	
		HashMap<String, Object> map = service.setTable("categories").column("id","pid","title").where("id="+bean.getCategory_id()).selectMap();
		request.setAttribute("menu_title_1", map);
		int topid=(int) map.get("pid");
		if(topid!=0) {
			HashMap<String, Object> kap = service.column("id","pid","title").where("id="+topid).selectMap();
			request.setAttribute("menu_title_0", kap);
		}		
	}

}
